package com.etc.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import com.etc.dao.OrderMapper;
import com.etc.entity.Orders;
import com.etc.service.OrderService;
import com.etc.util.PageData;

@Service
public class OrderServiceImpl implements OrderService {

	@Resource
	private OrderMapper om;

	@Override
	public boolean deleteByPrimaryKey(Integer orderid) {
		// TODO Auto-generated method stub
		return om.deleteByPrimaryKey(orderid) > 0;
	}

	@Override
	public boolean insert(Orders record) {
		// TODO Auto-generated method stub
		return om.insert(record) > 0;
	}

	@Override
	public boolean insertSelective(Orders record) {
		// TODO Auto-generated method stub
		return om.insertSelective(record) > 0;
	}

	@Override
	public Orders selectByPrimaryKey(Integer orderid) {
		// TODO Auto-generated method stub
		return om.selectByPrimaryKey(orderid);
	}

	@Override
	public boolean updateByPrimaryKeySelective(Orders record) {
		// TODO Auto-generated method stub
		return om.updateByPrimaryKeySelective(record) > 0;
	}

	@Override
	public boolean updateByPrimaryKey(Orders record) {
		// TODO Auto-generated method stub
		return om.updateByPrimaryKey(record) > 0;
	}

	@Override
	public PageData<Orders> selectAllByPage(int page, int pageSize, @Param("content") String content) {
		int start = (page-1) * pageSize;
		//int count = om.selectCount(orderid, userid)
		List<Orders> data = om.selectAllByPage(start, pageSize, content);
		int count = om.selectCount(content);
		PageData<Orders> pd = new PageData<>(data, count, pageSize, page);
		return pd;
	}
	
	/**
	 * 前端页面的订单分页
	 */
	@Override
	public PageData<Orders> selectByPage(int page, int limit, String content, int userid) {
		// TODO Auto-generated method stub
		int start = (page-1) * limit;
		List<Orders> list = om.selectByPage(start, limit, content, userid);
		int count = om.selectCountByUserid(content, userid);
		PageData<Orders> pd = new PageData<>(list, count, limit, page);
		return pd;
	}

	
}
